package org.cashbook.core.objects.transaction;

import java.util.ArrayList;
import java.util.Iterator;

public class TransactionList extends ArrayList<ITransaction> {
	private static final long serialVersionUID = 5389302010595918628L;

	@Override
	public boolean add(ITransaction transaction) {
		int index = 0;
		ITransaction oldTransaction;
		
		Iterator<ITransaction> iterator = this.iterator();
		while(iterator.hasNext()) {
			oldTransaction = iterator.next();
			if(oldTransaction.getStartDate().before(transaction.getStartDate()))
				index++;
			else
				break;
		}
		this.add(index, transaction);	
		return true;
	}
}
